<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<tr:document xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:c="http://java.sun.com/jstl/core"
             xmlns:fn="http://java.sun.com/jsp/jstl/functions"
             xmlns:mias="http://www.monsters.inc/mias"
             xmlns:tr="http://myfaces.apache.org/trinidad">
<!-- 
     Everything outside the ui:composition tag will be ignored by Facelets!
-->
<ui:composition>
  <!--
      This component is meant for use inside a component that expects selectItems.
      Arguments:
      - items     should evaluate to an array or list with items, where items
                  can be any bean object
      - itemValue should be the name of the property of the bean that will contain 
                  the value that will be used when the option is chosen
      - itemLabel should be the name of the property if the bean that will contain
                  the label that will be shown in the choice list. itemLabel and
                  itemValue may be equal.
   -->
  
  <c:if test="#{not (empty itemValue and empty itemLabel)}" > 
    <c:if test="#{empty itemValue}">
      <c:set var="itemValue" value="#{id}" />
    </c:if>
    <c:if test="#{empty itemLabel}">
      <c:set var="itemLabel" value="#{id}" />
    </c:if>
  </c:if>
   
  <c:if test="#{empty itemValue and empty itemLabel}" >
    <c:forEach var="item" items="#{items}">
      <tr:selectItem value="#{item}" label="#{item}" />
    </c:forEach>    
  </c:if>
  
  <c:if test="#{not (empty itemValue and empty itemLabel)}" > 
    <c:forEach var="item" items="#{items}">
      <c:choose>
        <c:when test="#{itemValue eq 'id'}">
          <tr:selectItem value="#{item}" label="#{item[itemLabel]}" />
        </c:when>
        <c:otherwise>
          <tr:selectItem value="#{item[itemValue]}" label="#{item[itemLabel]}" />
        </c:otherwise>
      </c:choose>
    </c:forEach>
  </c:if>
</ui:composition>
</tr:document>
